//748.最短补全词
//思路：哈希表

char * shortestCompletingWord(char * licensePlate, char ** words, int wordsSize){
    int hash[26] = {0};
    while(*licensePlate != '\0')
    {
        if(*licensePlate >= 'A' && *licensePlate <= 'Z')
            hash[(*licensePlate)-'A']++;
        else if(*licensePlate >= 'a' && *licensePlate <= 'z')
            hash[(*licensePlate)-'a']++;

        licensePlate++;
    }

    int index = -1;
    for(int i = 0; i < wordsSize; i++)
    {
        int tmp[26] = {0};
        for(int j = 0; j < strlen(words[i]); j++)
        {
            tmp[words[i][j]-'a']++;
        }

        int k = 0;
        while(k<26 && hash[k]<=tmp[k])
        {
            k++;
        }

        if(26 == k)
        {
            if(-1 == index)
            {
                index = i;
            }
            else
            {
                if(strlen(words[i]) < strlen(words[index]))
                {
                    index = i;
                }
            }
        }
    }
    return words[index];
}